<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>数据库管理</title>
		<link rel="stylesheet" href="/static/css/layui.css" />
		<link rel="stylesheet" href="/static/css/common.css" />
	</head>
	<body class="container">
		
		<div class="layui-card">
			<div class="layui-card-body">
				<table id="db-table" lay-filter="db-table"></table>
			</div>
		</div>

		<script type="text/html" id="db-bar">
			<button class="layui-btn layui-btn-primary layui-btn-sm" lay-event="back"><i class="layui-icon layui-icon-ok-circle"></i></button>
		    <button class="layui-btn layui-btn-danger layui-btn-sm" lay-event="remove"><i class="layui-icon layui-icon-delete"></i></button>
		</script>

		

		<script type="text/html" id="db-loginTime">
			{{layui.util.toDateString(d.login_time*1000, 'yyyy-MM-dd HH:mm:ss')}}
		</script>
		
		<script src="/static/js/layui.js"></script>
		<script>
			layui.config({
					base: "/static/js/"
				}).extend({
					api: 'api'
				}).use([
					'api'
				], function() {
				let table = layui.table;
				let form = layui.form;
				let $ = layui.jquery;
				let common = layui.common;
				let api = layui.api;

				let MODULE_PATH = "./";

				let cols = [
					[
						{
							title: '文件名',
							field: 'name',
							align: 'center'
						},
						{
							title: '操作',
							toolbar: '#db-bar',
							align: 'center',
							width: 130
						}
					]
				]

				table.render({
					elem: '#db-table',
					url: api.apiUrl + 'db/backupFile',
					headers : api.getHeader(),
					parseData: function(res) {
						//console.log(res)
						return {
							"code": res.code, //解析接口状态
							"msg": res.message, //解析提示文本
							"count": res.data.count, //解析数据长度
							"data": res.data.list //解析数据列表
						};
					},
					page: false,
					cols: cols,
					skin: 'line',

					toolbar: '#db-toolbar',
					defaultToolbar: [{
						title: '刷新',
						layEvent: 'refresh',
						icon: 'layui-icon-refresh',
					}, 'filter', 'print', 'exports']
				});

				table.on('tool(db-table)', function(obj) {
					if (obj.event === 'remove') {
						window.remove(obj);
					} else if (obj.event === 'back') {
						window.back(obj);
					}
				});


				window.back = function(obj) {
					layer.confirm('确定要还原?', {icon: 3, title:'提示'}, function(index){
		                layer.close(index);
		                api.post('db/reback',{file : obj.data.name}, res => {
							layer.msg('还原成功',{icon:1,time:1000});
						}, err => {
							layer.msg('还原失败',{icon:2,time:1000});
						})
		            });
				}
				window.remove = function(obj){
		            layer.confirm('确定要删除?', {icon: 3, title:'提示'}, function(index){
		                layer.close(index);
		                api.post('db/delback',{file : obj.data.name}, res => {
							layer.msg('删除成功',{icon:1,time:1000},() => {
								obj.del();
							});
						}, err => {
							//layer.msg('删除失败',{icon:2,time:1000});
						})
		            });
		        }
				

				window.refresh = function(param) {
					table.reload('db-table');
				}
			})
		</script>
	</body>
</html>
